// #include "StdAfx.h"
#include "tfBondInfo.h"
//#include "Database.h"
//#include "BondContainer.h"

// #ifdef _DEBUG
// #undef THIS_FILE
// static char THIS_FILE[] = __FILE__;
// #endif

//////////////////////////////////////////////////////////////////////
// class CFutureInfo

CFutureInfo::CFutureInfo()
{
	Clear();
}

CFutureInfo::~CFutureInfo()
{
}

void CFutureInfo::Clear( )
{
	m_dwMarket = 0;							// 市场类型
	memset(m_TF_Key,0,sizeof(m_TF_Key));						//合约的key
	memset(m_TF_ID,0,sizeof(m_TF_ID));							//合约代码
	memset(m_TF_ShortName,0,sizeof(m_TF_ShortName));					//合约简称 
	memset(m_sPinyin,0,sizeof(m_sPinyin));					//拼音
	m_Delivery_Month = 0;
	m_Last_Trading_Day = 0;
	m_Delivery_Date = 0;
	m_BondTerm = 0;
	m_Deliverable_maturity_Start = 0;
	m_Deliverable_maturity_End = 0;
	memset(m_Quoted_Way,0,sizeof(m_Quoted_Way));
	m_Min_Change = 0.f;
	memset(m_Trading_Time,0,sizeof(m_Trading_Time));
	memset(m_Last_Day_Trading_Time,0,sizeof(m_Last_Day_Trading_Time));
	m_Price_Limit = 0.f;
	m_Lowest_Margins = 0.f;
	memset(m_Delivery_Way,0,sizeof(m_Delivery_Way));
	memset(m_Listed_Market,0,sizeof(m_Listed_Market));
	memset(m_Is_Tradable,0,sizeof(m_Is_Tradable));				//'Y'--可交易，“N”--不可交易
	m_type = 0;

	memset(m_TradingDay,0,sizeof(m_TradingDay));	//	交易日
	memset(m_InstrumentID,0,sizeof(m_InstrumentID));	//	合约代码
	memset(m_InstrumentName,0,sizeof(m_InstrumentName));//	合约名称
	memset(m_ExchangeID,0,sizeof(m_ExchangeID));	//	交易所代码
	memset(m_ExchangeInstID,0,sizeof(m_ExchangeInstID));//	合约在交易所的代码
	m_datebegin = 0;		//	起始日期
	m_LastPrice = 0.f;		//	最新价
	m_PreSettlementPrice = 0.f;	//	上次结算价
	m_PreClosePrice = 0.f;	//	昨收盘
	m_PreOpenInterest = 0;	//	昨持仓量
	m_OpenPrice = 0.f;		//	今开盘
	m_HighestPrice = 0.f;		//	最高价
	m_LowestPrice = 0.f;		//	最低价
	m_Volume = 0;			//	数量
	m_Turnover = 0;			//	成交金额
	m_LastVolume = 0;		//	最新数量
	m_LastTurnover = 0;		//	最新成交金额
	m_OpenInterest = 0;		//	持仓量
	m_ClosePrice = 0.f;		//	今收盘
	m_SettlementPrice = 0.f;	//	本次结算价
	m_UpperLimitPrice = 0.f;	//	涨停板价
	m_LowerLimitPrice = 0.f;	//	跌停板价
	m_CurrDelta = 0.f;		//	今虚实度
	m_PreDelta = 0.f;			//	昨虚实度
	memset(m_UpdateTime,0,sizeof(m_UpdateTime));	//	最后修改时间(HH:MM:SS)
	m_UpdateMillisec = 0;	//	最后修改毫秒
	m_AveragePrice = 0.f;		//	当日均价
	m_BidPrice1 = 0.f;		//	申买价一
	m_BidVolume1 = 0;		//	申买量一
	m_AskPrice1 = 0.f;		//	申卖价一
	m_AskVolume1 =0;		//	申卖量一
	m_BidPrice2 = 0.f;		//	申买价二
	m_BidVolume2 = 0;		//	申买量二
	m_AskPrice2 = 0.f;		//	申卖价二
	m_AskVolume2 = 0;		//	申卖量二
	m_BidPrice3 = 0.f;		//	申买价三
	m_BidVolume3 = 0;		//	申买量三
	m_AskPrice3 = 0.f;		//	申卖价三
	m_AskVolume3 = 0;		//	申卖量三
	m_BidPrice4 = 0.f;		//	申买价四
	m_BidVolume4 = 0;		//	申买量四
	m_AskPrice4 = 0.f;		//	申卖价四
	m_AskVolume4 = 0;		//	申卖量四
	m_BidPrice5 = 0.f;		//	申买价五
	m_BidVolume5 = 0;		//	申买量五
	m_AskPrice5 = 0.f;		//	申卖价五
	m_AskVolume5 = 0;		//	申卖量五
}

CFutureInfo & CFutureInfo::operator = ( const CFutureInfo & bi ){
	m_dwMarket = bi.m_dwMarket;							// 市场类型
	memcpy(m_TF_Key,bi.m_TF_Key,sizeof(m_TF_Key));						//合约的key
	memcpy(m_TF_ID,bi.m_TF_ID,sizeof(m_TF_ID));							//合约代码
	memcpy(m_TF_ShortName,bi.m_TF_ShortName,sizeof(m_TF_ShortName));					//合约简称 
	memcpy(m_sPinyin,bi.m_sPinyin,sizeof(m_sPinyin));					//拼音
	m_Delivery_Month = bi.m_Delivery_Month;
	m_Last_Trading_Day = bi.m_Last_Trading_Day;
	m_Delivery_Date = bi.m_Delivery_Date;
	m_BondTerm = bi.m_BondTerm;
	m_Deliverable_maturity_Start = bi.m_Deliverable_maturity_Start;
	m_Deliverable_maturity_End = bi.m_Deliverable_maturity_End;
	memcpy(m_Quoted_Way,bi.m_Quoted_Way,sizeof(m_Quoted_Way));
	m_Min_Change = bi.m_Min_Change;
	memcpy(m_Trading_Time,bi.m_Trading_Time,sizeof(m_Trading_Time));
	memcpy(m_Last_Day_Trading_Time,bi.m_Last_Day_Trading_Time,sizeof(m_Last_Day_Trading_Time));
	m_Price_Limit = bi.m_Price_Limit;
	m_Lowest_Margins = bi.m_Lowest_Margins;
	memcpy(m_Delivery_Way,bi.m_Delivery_Way,sizeof(m_Delivery_Way));
	memcpy(m_Listed_Market,bi.m_Listed_Market,sizeof(m_Listed_Market));
	memcpy(m_Is_Tradable,bi.m_Is_Tradable,sizeof(m_Is_Tradable));				//'Y'--可交易，“N”--不可交易
	m_type = bi.m_type;
	m_kdata = bi.m_kdata;

	memcpy(m_TradingDay,bi.m_TradingDay,sizeof(m_TradingDay));	//	交易日
	memcpy(m_InstrumentID,bi.m_InstrumentID,sizeof(m_InstrumentID));	//	合约代码
	memcpy(m_InstrumentName,bi.m_InstrumentName,sizeof(m_InstrumentName));//	合约名称
	memcpy(m_ExchangeID,bi.m_ExchangeID,sizeof(m_ExchangeID));	//	交易所代码
	memcpy(m_ExchangeInstID,bi.m_ExchangeInstID,sizeof(m_ExchangeInstID));//	合约在交易所的代码
	m_datebegin = bi.m_datebegin;		//	起始日期
	m_LastPrice = bi.m_LastPrice;		//	最新价
	m_PreSettlementPrice = bi.m_PreSettlementPrice;	//	上次结算价
	m_PreClosePrice = bi.m_PreClosePrice;	//	昨收盘
	m_PreOpenInterest = bi.m_PreOpenInterest;	//	昨持仓量
	m_OpenPrice = bi.m_OpenPrice;		//	今开盘
	m_HighestPrice = bi.m_HighestPrice;		//	最高价
	m_LowestPrice = bi.m_LowestPrice;		//	最低价
	m_Volume = bi.m_Volume;			//	数量
	m_Turnover = bi.m_Turnover;			//	成交金额
	m_LastVolume = bi.m_LastVolume;		//	最新数量
	m_LastTurnover = bi.m_LastTurnover;		//	最新成交金额
	m_OpenInterest = bi.m_OpenInterest;		//	持仓量
	m_ClosePrice = bi.m_ClosePrice;		//	今收盘
	m_SettlementPrice = bi.m_SettlementPrice;	//	本次结算价
	m_UpperLimitPrice = bi.m_UpperLimitPrice;	//	涨停板价
	m_LowerLimitPrice = bi.m_LowerLimitPrice;	//	跌停板价
	m_CurrDelta = bi.m_CurrDelta;		//	今虚实度
	m_PreDelta = bi.m_PreDelta; 		//	昨虚实度
	memcpy(m_UpdateTime,bi.m_UpdateTime,sizeof(m_UpdateTime));	//	最后修改时间(HH:MM:SS)
	m_UpdateMillisec = bi.m_UpdateMillisec;	//	最后修改毫秒
	m_AveragePrice = bi.m_AveragePrice;		//	当日均价
	m_BidPrice1 = bi.m_BidPrice1;		//	申买价一
	m_BidVolume1 = bi.m_BidVolume1;		//	申买量一
	m_AskPrice1 = bi.m_AskPrice1 ;		//	申卖价一
	m_AskVolume1 =bi.m_AskVolume1;		//	申卖量一
	m_BidPrice2 = bi.m_BidPrice2 ;		//	申买价二
	m_BidVolume2 = bi.m_BidVolume2;		//	申买量二
	m_AskPrice2 = bi.m_AskPrice2 ;		//	申卖价二
	m_AskVolume2 = bi.m_AskVolume2;		//	申卖量二
	m_BidPrice3 = bi.m_BidPrice3 ;		//	申买价三
	m_BidVolume3 = bi.m_BidVolume3;		//	申买量三
	m_AskPrice3 = bi.m_AskPrice3 ;		//	申卖价三
	m_AskVolume3 = bi.m_AskVolume3;		//	申卖量三
	m_BidPrice4 = bi.m_BidPrice4 ;		//	申买价四
	m_BidVolume4 = bi.m_BidVolume4;		//	申买量四
	m_AskPrice4 = bi.m_AskPrice4 ;		//	申卖价四
	m_AskVolume4 = bi.m_AskVolume4;		//	申卖量四
	m_BidPrice5 = bi.m_BidPrice5 ;		//	申买价五
	m_BidVolume5 = bi.m_BidVolume5;		//	申买量五
	m_AskPrice5 = bi.m_AskPrice5 ;		//	申卖价五
	m_AskVolume5 = bi.m_AskVolume5;		//	申卖量五

	return *this;
}

bool CFutureInfo::IsEqualTo( const char * szFutureID ){
	if(strcmp(m_TF_ID, szFutureID)==0)return true;
	return false;
}

bool CFutureInfo::IsKeyEqualTo( const char * szFutureKey ){
	if(strcmp(m_TF_Key, szFutureKey)==0)return true;
	return false;
}

DWORD CFutureInfo::GetMarket( )
{
	return m_dwMarket;
}

void CFutureInfo::SetMarket( DWORD dwMarket )
{
	m_dwMarket	=	dwMarket;
// 	if( CBondData::marketSHSE == dwMarket )
// 		m_type	|=	CBondData::markShanghai;
// 	if( CBondData::marketSZSE == dwMarket )
// 		m_type	|=	CBondData::markShenzhen;
}

const char * CFutureInfo::GetFutureKey( )
{
	return m_TF_Key;
}

const char * CFutureInfo::GetFutureCode( )
{
	return m_TF_ID;
}

bool	CFutureInfo::SetFutureKey( const char * szKey )
{
	memset(m_TF_Key, 0, sizeof(m_TF_Key) );
	if( NULL == szKey )
		return false;
	FIELDCOPY(m_TF_Key,szKey);
	return true;
}

bool	CFutureInfo::SetFutureCode( const char * szCode, bool bClear )
{
	if( NULL == szCode || strlen(szCode) <= 0 )
	{
		if(bClear)Clear();
		return false;
	}

	if( IsEqualTo( szCode ) )
	{
		return IsValidFuture();
	}

	if(bClear)Clear( );

	memset(m_TF_ID, 0, sizeof(m_TF_ID) );
	FIELDCOPY(m_TF_ID,szCode);
	return true;
}

const char * CFutureInfo::GetFutureName( )
{
	return m_InstrumentName;
}

void	CFutureInfo::SetFutureName( const char * szName )
{
	memset(m_InstrumentName, 0, sizeof(m_InstrumentName) );
	if( NULL == szName )
		return;
	FIELDCOPY(m_InstrumentName,szName);
}

bool	CFutureInfo::IsValidFuture( )		// 债券信息是否正确
{
	return true;
}

int CFutureInfo::DigitBit( )
{
	return 3;
}
